{include file="public/header" /}
<body class="gray-bg">
<div class="wrapper wrapper-content">
    <div class="ibox float-e-margins">
        <div class="ibox-content">
            <div class="row">
                <!--搜索框开始-->
                <div class="col-sm-12">
                    <div class="layui-form layui-form-item">

                        <div class="layui-input-inline" style="margin-top: 5px">
                            <input type="text"  name="start" onfocus="wk.lay_date(this);" class="layui-input layer-date search" placeholder="开始时间"/>
                        </div>

                        <div class="layui-input-inline" style="margin-top: 5px">
                            <input type="text"  name="end" onfocus="wk.lay_date(this);" class="layui-input layer-date search" placeholder="结束时间"/>
                        </div>

                        <div class="layui-col-md6 layui-input-inline" style="margin-top: 5px">
                            <input type="text" id="keyword" class="layui-input search" name="keyword" value="" placeholder="标题"/>
                        </div>
                        <div class="layui-col-md6 layui-input-inline" style="margin-top: 5px">
                            <select name="topic_type" xm-select="select2" xm-select-search="" xm-select-radio="" xm-select-search-type="dl">
                                {foreach name="topic_type" item="vv"}
                                <option value="{$vv.topic_type_id}">{$vv.topic_type_name}</option>
                                {/foreach}
                            </select>
                        </div>
                        <div class="layui-col-md6 layui-input-inline" style="margin-top: 5px">
                            <select name="province" lay-search="" id="province"  lay-filter="province">
                                <option value="">全部</option>
                                <option value="1" >显示</option>
                                <option value="2" >隐藏</option>
                            </select>
                        </div>
                        <div class="layui-input-inline" style="margin-top: 5px">
                            <button class="layui-btn" lay-submit="" lay-filter="LAY-search">立即搜索</button>
                            <button  class="layui-btn layui-btn-normal" id="empty"  lay-submit="" lay-filter="LAY-search">重置</button>
                        </div>
                    </div>
                </div>

                <div class="col-sm-12">
                    <div class="input-group" >
                        <!--<button class="btn btn-primary" type="button" onclick="wk.href('{:url('add')}');">-->
                            <!--<i class="fa fa-plus"></i> 添加-->
                        <!--</button>-->
                    </div>
                </div>
            </div>
            <div class="hr-line-dashed"></div>

            <div class="example-wrap">
                <div class="example">
                    <table class="layui-hide" id="test" lay-filter="testReload"></table>
                    <!--状态显示模板-->
                    <script type="text/html" id="imgTpl">
                        <img src="{{d.banner_thumb}}" class="table-img layui-cricle" onerror="this.src='/static/admin/images/head_default.gif'"/>
                    </script>
                    <script type="text/html" id="topic_is_show">
                        {{# if(d.topic_is_show == 1){ }}
                        显示
                        {{# } }}
                        {{# if(d.topic_is_show == 2){ }}
                        隐藏
                        {{# } }}
                    </script>
                    <script type="text/html" id="opeBar">
                        {{# if(d.topic_is_show == 1){ }}
                        <a href="javascript:;" onclick="wk.confirm('{{d.topic_id}}','{:url('down')}','确定隐藏吗?')" class="btn btn-warning btn-xs m-r-xs" title="隐藏">隐藏</a>
                        {{# } }}
                        {{# if(d.topic_is_show ==2){ }}
                        <a href="javascript:;" onclick="wk.confirm('{{d.topic_id}}','{:url('up')}','确定显示吗?')" class="btn btn-primary btn-xs m-r-xs" title="显示">显示</a>
                        {{# } }}
                        <a href="javascript:;" onclick="wk.confirm('{{d.topic_id}}','{:url('del')}','确定删除吗?')" class="btn btn-primary btn-xs m-r-xs" title="删除">删除</a>
                        <a href="javascript:;" onclick="wk.href('{:url('detail')}?topic_id={{d.topic_id}}')" class="btn btn-primary btn-xs m-r-xs" title="详情">详情</a>
                        <a href="javascript:;" onclick="wk.href('{:url('entry')}?topic_id={{d.topic_id}}')" class="btn btn-primary btn-xs m-r-xs" title="留言列表">留言列表</a>

                    </script>
                </div>
            </div>
        </div>
    </div>
</div>
{include file="public/footer" /}
<script>
    //layui渲染数据表格
    layui.use('table', function () {
        var table = layui.table
                , form = layui.form;
        table.render({
            elem: '#test'
            , url: '{:url("topic/index")}'
            ,response: {
                statusCode: 220 //成功的状态码，默认：0
            }
            , page: true
            , size: 'lg' //sm小尺寸的表格 lg大尺寸
            , cellMinWidth: 150
            , limits: [5, 10, 15, 20, 25, 30]
            , limit: "{:config('pages')}"
            , loading: true
            , id: 'testReload'
            , cols: [[
//                {type:'numbers', width: 80, title: '序号'}
                 {field: 'topic_id', width: 80, title: '话题ID', align: 'center'}
                ,{field: 'topic_title', width: 150, title: '话题标题', align: 'center'}
                ,{field: 'topic_type_name', width: 150, title: '话题分类', align: 'center'}
                ,{field: 'user_username', width: 150, title: '发布人', align: 'center'}
                , {field: 'topic_fb_time', width: 160, title: '发布时间', align: 'center'}
                , {field: 'user_phone', width: 160, title: '发布手机号码', align: 'center'}
                , {field: 'dz_num', width: 120, title: '点赞数量', align: 'center',sort: true}
                , {field: 'like_num', width: 120, title: '收藏数量', align: 'center',sort: true}
                , {field: 'message_num', width: 120, title: '留言数量', align: 'center',sort: true}
                , {field: 'topic_is_show', width: 90, title: '状态', align: 'center',templet:"#topic_is_show"}
                , {fixed: 'right', width:250, title: '操作', align: 'center', toolbar: '#opeBar'}
            ]]
            ,done: function (res, curr, count) {
                $('.layui-cricle').viewer();//图片查看器
            }
        });
        //监听单元格编辑
        table.on('edit(testReload)', function(obj){
            var value = obj.value //得到修改后的值
                    ,data = obj.data //得到所在行所有键值
                    ,field = obj.field; //得到字段
            // layer.msg('[ID: '+ data.id +'] ' + field + ' 字段更改为：'+ value);
            var patrn = /^[0-9]*$/;
            if(!patrn.test(value)){
                layer.msg('排序值只能为数字',{icon:2,time:1500,shade: 0.1},function(){
                    //重载当前页表格
                    $(".layui-laypage-btn").click();
                });
                return false;
            }
            wk.changeSort(data.banner_id,"{:url('sort')}",field,value);
        });
        //批量操作
        var $ = layui.$, active = {
            //批量删除
            batchDel:function () {
                wk.batchDel(getIds(),"{:url('del')}");
            }
        };
        $('.layuiBtn').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
        var getIds = function () {
            var ids = [];
            var checkStatus = table.checkStatus('testReload')
                    ,data = checkStatus.data;
            $.each(data,function(index,item){
                ids.push(item['s_id'])
            });
            return ids;
        }
    });
</script>
</body>
</html>